package com.shrcl.engineerprocess.domain.impl;

import com.google.common.base.Objects;
import com.shrcl.engineerprocess.domain.BusinessProcessDelete;
import com.shrct.businessprocess.common.RCTaskProxy;
import edu.fudan.langlab.domain.workflow.BusinessProcess;
import edu.fudan.langlab.domain.workflow.ProcessTask;
import edu.fudan.langlab.domain.workflow.Token;
import edu.fudan.mylang.pf.BaseService;
import edu.fudan.mylang.pf.IGenericQuery;
import java.util.Collection;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.springframework.stereotype.Service;

@Service("com.shrcl.engineerprocess.domain.BusinessProcessDelete")
public class BusinessProcessDeleteImpl extends BaseService implements BusinessProcessDelete {
  public void deleteBusinessProcess(final BusinessProcess bp) {
    Collection<Token> _tokens = bp.getTokens();
    final Procedure1<Token> _function = new Procedure1<Token>() {
        public void apply(final Token it) {
          final ProcessTask pt = it.getProcessTask();
          IGenericQuery<RCTaskProxy> query=getObjectFactory().createGenericQuery(RCTaskProxy.class,"select rtp from com.shrct.businessprocess.common.impl.RCTaskProxyImpl as rtp   where ((rtp.task) = (:pt)) and  rtp.active = 1      ").setParameter("pt",pt);
          final RCTaskProxy rctask = query.uniqueResult();
          boolean _notEquals = (!Objects.equal(rctask, null));
          if (_notEquals) {getObjectFactory().delete(rctask);
            
          }getObjectFactory().delete(pt);
          
        }
      };
    IterableExtensions.<Token>forEach(_tokens, _function);getObjectFactory().delete(bp);
    
  }
}
